package il.ac.tau.cvws.scrabblesidekick.client.ui.view;

import il.ac.tau.cvws.scrabblesidekick.client.R;
import il.ac.tau.cvws.scrabblesidekick.shared.util.math.Point;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.View;

/* The border view displayed within the camera view.
 */
@SuppressLint({ "DrawAllocation", "ViewConstructor" })
public class BorderView extends View 
{
    private final Paint   _paint;
    private final Point[] _border;

    public BorderView(Context context, Point[] points) 
    {
        super(context);
        
        _border = points;
        
        _paint = new Paint();
        _paint.setColor(getResources().getColor(R.color.yellow));
        _paint.setDither(true);
        _paint.setStyle(Paint.Style.STROKE);
        _paint.setStrokeJoin(Paint.Join.ROUND);
        _paint.setStrokeCap(Paint.Cap.ROUND);
        _paint.setPathEffect(new DashPathEffect(new float[] {8, 10}, 0));
        _paint.setStrokeWidth(3);
    }

    @Override
    public void onDraw(Canvas canvas) 
    {
 		Path path = new Path();
 		
 		path.moveTo((int)_border[0].x, (int)_border[0].y);
 		path.lineTo((int)_border[1].x, (int)_border[1].y);
 		path.lineTo((int)_border[2].x, (int)_border[2].y);
 		path.lineTo((int)_border[3].x, (int)_border[3].y);
 		path.lineTo((int)_border[0].x, (int)_border[0].y);
 		
 		canvas.drawPath(path, _paint);
    }
}
